require "Dialogs"

Arena.ResizeImmediate(565, 130)
Player.sprite.alpha = 0

timer = 0
phase = Encounter["phase"]
progress = Encounter["progress"]
if Encounter["FUN"][1] == "Rare" and Encounter["FUN"][2] == 3 and phase > 1 and phase < 4 then
	Heart = CreateSprite("Undertale/Game Over/Soul", "Top")
	Audio.PlaySound("flee")
else
	if phase == 3 and progress == 0 then
		Heart = CreateSprite("Undertale/Game Over/Soul", "Top")
		Encounter.Call("AttackAnim", 1)
	else
		Heart = CreateSprite("HeartFlee 1", "Top")
		Audio.PlaySound("flee")
	end
end
Heart.MoveTo(65, 160)
Heart.color = Player.sprite.color
Paps = {X = Encounter["Legs"].x, Y = Encounter["Legs"].y}
Pos = {X = 65, Y = 160}
ShakeL = {}


if phase > 1 then
	if Encounter["FUN"][1] == "Rare" and Encounter["FUN"][2] == 3 and phase < 4 then
		Flee = CreateSprite("Flee 1 "..GetAlMightyGlobal("Idioma"),"Top")
		Flee.SetAnimation({"Flee 1 "..GetAlMightyGlobal("Idioma"),"Flee 2 "..GetAlMightyGlobal("Idioma")}, 5/60)
		Flee.MoveTo(139, 163)
		Encounter["flee"] = false
		Especial = true
		if phase == 3 then
			Sans = {X = Encounter["Sans"]["Legs"].x, Y = Encounter["Sans"]["Legs"].y}
			if progress == 2 then
				if Encounter["Undyne"] then Undyne = {X = Encounter["Undyne"]["Legs"].x, Y = Encounter["Undyne"]["Legs"].y} end
			end
		end
	else
		if phase < 4 then
			Encounter["flee"] = false
		end
		if phase == 3 then
			Sans = {X = Encounter["Sans"]["Legs"].x, Y = Encounter["Sans"]["Legs"].y}
			if progress == 2 then
				if Encounter["Undyne"] then Undyne = {X = Encounter["Undyne"]["Legs"].x, Y = Encounter["Undyne"]["Legs"].y} end
			end
		end
		if phase < 4 then
			Spare = CreateSprite("Specials/Spare "..GetAlMightyGlobal("Idioma"), "Top")
			Spare.MoveTo(146, 189)
			table.insert(ShakeL, {Sprite = Spare})
			if GetAlMightyGlobal("Idioma") == "English" then
				Flee = {CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/ast", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Mayuscula/F", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/l", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/e", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/e", "Top")}
			elseif GetAlMightyGlobal("Idioma") == "Spanish" then
				Flee = {CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/ast", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Mayuscula/H", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/u", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/i", "Top"), CreateSprite("Dialogs Library Sprites/Box/Fonts/uidialog/Minuscula/r", "Top")}
			end
			local position = 108.5
			for i=1,5 do
				if phase == 3 and progress == 0 then
					Flee[i].MoveTo(position + 110, 413 - math.max(2 - i, 0))
				else
					Flee[i].MoveTo(position, 163 - math.max(2 - i, 0))
				end
				position = position + Flee[i].width + 3
				if i == 1 then
					position = position - 11
				end
				table.insert(ShakeL, {Sprite = Flee[i]})
			end
		end
		if phase == 3 and progress == 0 then
			Black = CreateSprite("Pixel", "Top")
			Black.Scale(640, 480)
			Black.MoveTo(320, 240)
			Black.color = {0,0,0}
		end
	end
elseif phase == 1 and progress == 6 then
	Encounter.Call("SetHead", "Disappointed")
	Bajar = 20
end

HuesosSuelo = {}
Bones = {}
Shards = {}
GB = {}
Spears1 = {}
Spears2 = {}

function Update()
	DialogUpdate()
	shake = {}
	timer = timer + 1
	if Especial then
		if timer < 300 then
			Flee.x = Flee.x - 1
			if timer == 1 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Dialog("[noskip]Me voy de aquí. . .[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
				else
					Dialog("[noskip]I'm out of here. . .[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
				end
			elseif timer == 181 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Dialog("[noskip]Espera[w:10], que demo...[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
				else
					Dialog("[noskip]Wait[w:10], what the...[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
				end
			end
		elseif timer == 361 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Dialog("[noskip]No se suponía que esto...[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
			else
				Dialog("[noskip]This wasn't supposed to...[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
			end
		elseif timer == 541 then
			Dialog("[noskip]...[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
		elseif timer == 661 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Dialog("[noskip]Supongo que no me iré de aquí.", {X = 91, Y = 210}, nil, true, 1)
			else
				Dialog("[noskip]Guess I'm not out of here then.", {X = 91, Y = 210}, nil, true, 1)
			end
		elseif timer == 662 then
			if Dialogues[1] and not Dialogues[1].Activo then
				if string.sub(GetAlMightyGlobal("Archivimentazo"), 24, 24) == "0" then
					SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 23).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 25))
					Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 24}
				end
				Heart.Remove()
				Flee.Remove()
				Flee = nil
				Heart = nil
				Dialog("", "", "", "", 1)
				Player.sprite.alpha = 1
				if phase == 3 then
					Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Flee"
				end
				State("ENEMYDIALOGUE")
			else
				timer = 661
			end
		end
	else
		if phase == 1 then
			if timer < 40 then
				Pos.X = Pos.X - 1
				if timer%10 == 5 then
					Heart.Set("HeartFlee 2")
				elseif timer%10 == 0 then
					Heart.Set("HeartFlee 1")
				end
				if timer == 1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Dialog("[noskip]Me voy de aquí.[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
					else
						Dialog("[noskip]I'm out of here.[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
					end
				elseif timer == 35 then
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/Body", 10, 0), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = {MaxHeight = 200, Vel = 20}, Duration = 1/0})
					Audio.PlaySound("pierce")
				end
			elseif timer == 120 then
				Dialog("", "", "", "", 1)
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Bubble("[noskip][font:papyrus][voice:papyrus]Lo siento humano[w:10],\npero no puedo\ndejarte ir.", "rightwide", 490.5, 395 - (Bajar or 0), 40, 90, 1)
				else
					Bubble("[noskip][font:papyrus][voice:papyrus]Sorry human[w:10], but\nI can't let you\ngo.", "rightwide", 490.5, 395 - (Bajar or 0), 40, 90, 1)
				end
			elseif timer == 121 then
				if Bubbles[1] and not Bubbles[1].Activo then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus]No puedes\nescapar de tus\nproblemas.", "rightwide", 490.5, 395 - (Bajar or 0), 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus]You can't run\naway from your\nproblems.", "rightwide", 490.5, 395 - (Bajar or 0), 40, 90, 1)
					end
				else
					timer = timer - 1
				end
			elseif timer == 122 then
				if Bubbles[1] and not Bubbles[1].Activo then
					if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 1) == "0" then
						SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", "1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 2))
						if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
							SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
							Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
						end
					end
					for i=1,#HuesosSuelo do
						local bullet = HuesosSuelo[i - tableaux]
						bullet.Misil.Remove()
						if bullet.Head then
							bullet.Head.Remove()
						end
						if bullet.Legs then
							bullet.Legs.Remove()
						end
						bullet = nil
						table.remove(HuesosSuelo, i - tableaux)
						tableaux = tableaux + 1
					end
					tableaux = 0
					Heart.Remove()
					Heart = nil
					Player.sprite.alpha = 1
					State("ENEMYDIALOGUE")
				else
					timer = timer - 1
				end
			end
		elseif phase == 2 then
			if timer < 40 then
				Pos.X = Pos.X - 1
				if timer%10 == 5 then
					Heart.Set("HeartFlee 2")
				elseif timer%10 == 0 then
					Heart.Set("HeartFlee 1")
				end
				if timer == 35 then
					table.insert(Bones, {Body = CreateProjectileAbs("Bullets/Bones/Body", -20, 160), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = 120, Vel = 5})
					Audio.PlaySound("pierce")
				end
			elseif timer >= 42 and timer < 44 then
				Pos.X = Pos.X + 5
			elseif timer == 44 then
				for i=1,#Bones do
					local Datos = Bones[i]
					Datos.Vel = 0
				end
				Audio.PlaySound("slam")
				Heart.Set("Undertale/Game Over/Soul")
				Pos.X = 35
			elseif timer >= 45 and timer < 73 then
				Pos.X = math.min(Pos.X + 20, 594)
				for i=2,#ShakeL do
					local Datos = ShakeL[i - tableaux]
					Datos.X = math.min(math.max(Datos.X, Pos.X + 8 + Datos.Sprite.width/2 + 12*(i - 1)), 602 - Datos.Sprite.width/2 - math.min(-19 + 19*(i - 2), 0))
					if timer == 72 then
						for i=1,5 do
							local shard = CreateSprite("Soul Shards/1", "Top")
							shard.SetAnimation({"Soul Shards/1", "Soul Shards/2", "Soul Shards/3", "Soul Shards/4"}, 0.08)
							table.insert(Shards, {Sprite = shard, X = math.random(-40, 40), Y = math.random(60), Pos = {X = Datos.X, Y = Datos.Y}})
						end
						Datos.Sprite.Remove()
						table.remove(ShakeL, i - tableaux)
						tableaux = tableaux + 1
					end
				end
				tableaux = 0
			elseif timer == 73 then
				Audio.PlaySound("roughhit")
			elseif timer >= 74 and timer < 129 then
				Pos.X = Pos.X - 1
				if timer < 113 then
					Pos.Y = 160 + 40*math.sin(math.rad(180/40*(timer - 73)))
				else
					Pos.Y = 160 - 57/15*(timer - 113)
				end
			elseif timer == 214 then
				if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 2, 2) == "0" then
					SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 1).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 3))
					if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
						SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
						Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
					end
				end
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Encounter["enemies"][1].SetVar("currentdialogue", {"[noskip][effect:none][font:papyrus][voice:mad papyrus]A DÓNDE CREES\nQUE VAS?!"})
				else
					Encounter["enemies"][1].SetVar("currentdialogue", {"[noskip][effect:none][font:papyrus][voice:mad papyrus]WHERE DO YOU\nTHINK YOU ARE\nGOING?!"})
				end
				for i=1,#ShakeL do
					ShakeL[i - tableaux].Sprite.Remove()
					table.remove(ShakeL, i - tableaux)
					tableaux = tableaux + 1
				end
				tableaux = 0
				for i=1,#Shards do
					Shards[i - tableaux].Sprite.StopAnimation()
					Shards[i - tableaux].Sprite.Remove()
					table.remove(Shards, i - tableaux)
					tableaux = tableaux + 1
				end
				tableaux = 0
				for i=1,#Bones do
					local Datos = Bones[i - tableaux]
					Datos.Body.Remove()
					Datos.Head.Remove()
					Datos.Legs.Remove()
					table.remove(Bones, i - tableaux)
					tableaux = tableaux + 1
				end
				tableaux = 0
				Heart.Remove()
				Heart = nil
				Player.sprite.alpha = 1
				State("ENEMYDIALOGUE")
			end
			if timer >= 44 and timer < 49 then
				shake = {math.random(-4, 4), math.random(-4, 4)}
			elseif timer >= 73 and timer < 83 then
				shake = {math.random(-10, 10), math.random(-10, 10)}
			end
		elseif phase == 3 then
			if progress == 0 then
				if timer == 10 then
					Black.Remove()
					Black = nil
					Audio.PlaySound("st")
					Audio["menuconfirm"] = "menuconfirm"
				elseif timer == 40 then
					Encounter.Call("SetSansHead","Wink")
					Encounter["Sans"]["Body"].Set("Sans/Body/Joking")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans]whoops[w:10], supongo que ya\nno necesitarás esto.", "leftwide", 310.5, 335, 10, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans]whoops[w:10], guess you won't\nneed this anymore.", "leftwide", 310.5, 335, 10, 90, 1)
					end
				elseif timer == 41 then
					if Bubbles[1] and not Bubbles[1].Activo then
						Encounter.Call("SetSansHead","Normal")
						Encounter["Sans"]["Body"].Set("Sans/Body/Left")
						if GetAlMightyGlobal("Idioma") == "Spanish" then
							Bubble("[noskip][font:papyrus][voice:papyrus]Déjame solo...", "rightwide", 490.5, 395, 40, 90, 1)
						else
							Bubble("[noskip][font:papyrus][voice:papyrus]Let me just...", "rightwide", 490.5, 395, 40, 90, 1)
						end
					else
						timer = 40
					end
				elseif timer > 41 and timer <= 47 then
					if Bubbles[1] and not Bubbles[1].Activo then
						if timer == 42 then
							for i=2,#ShakeL do
								local Datos = ShakeL[i]
								Datos.Sprite.Dust(true)
							end
						end
						Encounter.Call("SetHead","Normal 3")
						Encounter["Head"].MoveTo(1 - 10 + math.abs(10*math.cos(math.rad(90/6*(timer - 41)))), 47 - 2 + (math.cos(math.rad(90/6*(timer - 41)))*math.cos(math.rad(90/6*(timer - 41))))*2)
						Encounter["Head"].rotation = 10 - math.abs(10*math.cos(math.rad(90/6*(timer - 41))))
					else
						timer = 41
					end
				elseif timer > 53 and timer <= 59 then
					Encounter.Call("SetHead","Normal 1")
					Encounter["Head"].MoveTo(1 - 10 + math.abs(10*math.cos(math.rad(90/6*(timer - 47)))), 47 - 2 + (math.cos(math.rad(90/6*(timer - 47)))*math.cos(math.rad(90/6*(timer - 47))))*2)
					Encounter["Head"].rotation = 10 - math.abs(10*math.cos(math.rad(90/6*(timer - 47))))
				elseif timer == 129 then
					Encounter["Animation"] = "Alocado"
					Encounter["vel"] = 0
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus]AHORA NO VAS A\nNINGUNA PARTE!", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus]NOW YOU'RE NOT\nGOING ANYWHERE!", "rightwide", 490.5, 395, 40, 90, 1)
					end
				elseif timer == 130 then
					if Bubbles[1] and not Bubbles[1].Activo then
						if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 3, 3) == "0" then
							SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 2).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 4))
							if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
								SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
								Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
							end
						end
						for i=1,#ShakeL do
							ShakeL[i - tableaux].Sprite.Remove()
							table.remove(ShakeL, i - tableaux)
							tableaux = tableaux + 1
						end
						tableaux = 0
						Heart.Remove()
						Heart = nil
						Player.sprite.alpha = 1
						Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Flee"
						State("ENEMYDIALOGUE")
					else
						timer = 129
					end
				end
			elseif progress == 1 then
				if timer < 25 then
					Pos.X = Pos.X - 1
					if timer%10 == 5 then
						Heart.Set("HeartFlee 2")
					elseif timer%10 == 0 then
						Heart.Set("HeartFlee 1")
					end
				elseif timer == 25 then
					Audio.PlaySound("ding")
					Encounter["Sans"]["Head"].SetAnimation({"Sans/Head/Power 1", "Sans/Head/Power 2"}, 0.04)
					Heart.Set("Undertale/Game Over/Soul")
					Pos.X = 320
					Pos.Y = 103
				elseif timer == 35 then
					Encounter["Sans"]["Head"].StopAnimation()
					Encounter["Sans"]["Head"].Set("Sans/Head/Normal")
					table.insert(GB, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Type = "Papyrus", Animacion = {DatosIniciales = {X = 690, Y = 530, rotation = 0}, DatosFinales = {X = 320, Y = 160, rotation = -90}}, Delay = 6, Duration = 30})
					Audio.PlaySound("gasterintro")
				elseif timer == 76 then
					for i=2,#ShakeL do
						ShakeL[i - tableaux].Sprite.Remove()
						table.remove(ShakeL, i - tableaux)
						tableaux = tableaux + 1
						Audio.PlaySound("dust")
					end
					tableaux = 0
				elseif timer == 130 then
					Encounter.Call("SetSansHead","Wink")
					Encounter["Sans"]["Body"].Set("Sans/Body/Joking")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:sans][voice:sans]ibas a alguna parte?", "leftwide", 230.5, 335, 10, 90, 1)
					else
						Bubble("[noskip][font:sans][voice:sans]were you going to\nsomewhere?", "leftwide", 230.5, 335, 10, 90, 1)
					end
				elseif timer == 131 then
					if Bubbles[1] and not Bubbles[1].Activo then
						if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 4, 4) == "0" then
							SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 3).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 5))
							if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
								SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
								Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
							end
						end
						Encounter.Call("SetSansHead","Normal")
						Encounter["Sans"]["Body"].Set("Sans/Body/Left")
						for i=1,#ShakeL do
							ShakeL[i - tableaux].Sprite.Remove()
							table.remove(ShakeL, i - tableaux)
							tableaux = tableaux + 1
						end
						tableaux = 0
						Heart.Remove()
						Heart = nil
						Player.sprite.alpha = 1
						Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Flee"
						State("ENEMYDIALOGUE")
					else
						timer = 130
					end
				end
			else
				if timer < 40 then
					Pos.X = Pos.X - 1
					if timer%10 == 5 then
						Heart.Set("HeartFlee 2")
					elseif timer%10 == 0 then
						Heart.Set("HeartFlee 1")
					end
					if timer == 35 then
						for i=0,7 do
							table.insert(Spears1, {Sprite = CreateSprite("Bullets/Spear","Top"), X = -30, Y = 90 + 20*i})
							Audio.PlaySound("spawn")
						end
					end
				elseif timer == 100 then
					Encounter.Call("SetHeadUndyne", "Hurt")
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][voice:undyne]Es en serio?![w:10]\nQUE PATÉTICO!", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][voice:undyne]Are you serious?![w:10]\nHOW PATHETIC!", "rightwide", 490.5, 395, 40, 90, 1)
					end
				elseif timer == 101 then
					if Bubbles[1] and not Bubbles[1].Activo then
						table.insert(Spears2, {Sprite = CreateSprite("Bullets/Spear","Top"), X = 135, Y = 63, Vel = 10, Direction = 90})
						for i=1,3 do
							Audio.PlaySound("pierce")
						end
					else
						timer = 100
					end
				elseif timer > 108 and timer < 228 then
					for i=2,#ShakeL do
						local Datos = ShakeL[i]
						Datos.X = (150.5 + 400/120*(timer - 108)) - (15*(4 - i) + 12*math.max(3 - i, 0))*math.cos(math.rad(-90/20*(timer - 108))) - math.max(2 - i, 0)*math.sin(math.rad(-90/20*(timer - 108)))
						Datos.Y = (163 + 250*math.sin(math.rad(180/120*(timer - 108)))) - math.max(2 - i, 0)*math.cos(math.rad(-90/20*(timer - 108))) - (15*(4 - i) + 12*math.max(3 - i, 0))*math.sin(math.rad(-90/20*(timer - 108)))
						Datos.Sprite.rotation = -90/20*(timer - 108)
					end
					if timer == 138 then
						if GetAlMightyGlobal("Idioma") == "Spanish" then
							Bubble("[noskip][voice:undyne]No voy a tolerar\nesto!", "rightwide", 490.5, 395, 40, 90, 1)
						else
							Bubble("[noskip][voice:undyne]I'm not going to\ntolerate this!", "rightwide", 490.5, 395, 40, 90, 1)
						end
					end
					if timer >= 218 and timer%4 == 2 then
						local randomizador = math.random(360)
						table.insert(Spears2, {Sprite = CreateSprite("Bullets/Spear","Top"), X = 550.5 - 100*math.cos(math.rad(randomizador)), Y = 163 - 100*math.sin(math.rad(randomizador)), Vel = 10, Direction = randomizador})
						for i=1,3 do
							Audio.PlaySound("toss")
						end
						Encounter.Call("SetHead", "Happy")
						Encounter.Call("SetSansHead", "Surprised")
					end
				elseif timer >= 228 and timer <= 332 then
					shake = {math.random(-2, 2), math.random(-2, 2)}
					if timer%4 == 2 then
						if timer <= 318 then
							local randomizador = math.random(360)
							table.insert(Spears2, {Sprite = CreateSprite("Bullets/Spear","Top"), X = 550.5 - 100*math.cos(math.rad(randomizador)), Y = 163 - 100*math.sin(math.rad(randomizador)), Vel = 10, Direction = randomizador})
							for i=1,3 do
								Audio.PlaySound("toss")
							end
						elseif timer == 322 then
							for i=1,5 do
								table.insert(Spears2, {Sprite = CreateSprite("Bullets/Spear","Top"), X = 550.5 - 20*(3 - i), Y = 163 - 100, Vel = 10, Direction = 90})
								Audio.PlaySound("pierce")
							end
						end
					elseif timer%4 == 0 then
						if timer < 332 then
							for i=2,#ShakeL do
								local Datos = ShakeL[i]
								Datos.X = math.max(math.min(Datos.X + math.random(-2, 2), 590.5), 510.5)
								Datos.Y = math.max(math.min(Datos.Y + math.random(-2, 2), 203), 123)
								Datos.Sprite.rotation = math.random(360)
							end
						else
							for i=2,#ShakeL do
								local Datos = ShakeL[i - tableaux]
								for i=1,5 do
									local shard = CreateSprite("Soul Shards/1", "Top")
									shard.SetAnimation({"Soul Shards/1", "Soul Shards/2", "Soul Shards/3", "Soul Shards/4"}, 0.08)
									table.insert(Shards, {Sprite = shard, X = math.random(-40, 40), Y = math.random(60), Pos = {X = Datos.X, Y = Datos.Y}})
								end
								Datos.Sprite.Remove()
								table.remove(ShakeL, i - tableaux)
								tableaux = tableaux + 1
							end
							tableaux = 0
						end
					end
				elseif timer == 452 then
					if Bubbles[1] and not Bubbles[1].Activo then
						Encounter.Call("SetHeadUndyne", "Mean Look")
						if GetAlMightyGlobal("Idioma") == "Spanish" then
							Bubble("[noskip][voice:undyne]Realmente pensaste\nque podrías escapar\nfácilmente?", "rightwide", 490.5, 395, 40, 90, 1)
						else
							Bubble("[noskip][voice:undyne]Did you really think\nyou could run away\nso easily?", "rightwide", 490.5, 395, 40, 90, 1)
						end
					else
						timer = 451
					end
				elseif timer == 453 then
					if Bubbles[1] and not Bubbles[1].Activo then
						if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 5, 5) == "0" then
							SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 4).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 6))
							if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
								SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
								Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
							end
						end
						for i=1,#ShakeL do
							ShakeL[i - tableaux].Sprite.Remove()
							table.remove(ShakeL, i - tableaux)
							tableaux = tableaux + 1
						end
						tableaux = 0
						for i=1,#Shards do
							Shards[i - tableaux].Sprite.StopAnimation()
							Shards[i - tableaux].Sprite.Remove()
							table.remove(Shards, i - tableaux)
							tableaux = tableaux + 1
						end
						tableaux = 0
						for i=1,#Spears1 do
							Spears1[i - tableaux].Sprite.Remove()
							table.remove(Spears1, i - tableaux)
							tableaux = tableaux + 1
						end
						tableaux = 0
						Encounter.Call("SetHead", "Normal 1")
						Encounter.Call("SetSansHead", "Normal")
						Encounter["moved"] = true
						Heart.Remove()
						Heart = nil
						Player.sprite.alpha = 1
						Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Flee"
						State("ENEMYDIALOGUE")
					else
						timer = 452
					end
				end
			end
		elseif phase == 4 then
			if timer < 40 then
				Pos.X = Pos.X - 1
				if timer%10 == 5 then
					Heart.Set("HeartFlee 2")
				elseif timer%10 == 0 then
					Heart.Set("HeartFlee 1")
				end
				if timer == 1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Dialog("[noskip]Me voy de aquí.[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
					else
						Dialog("[noskip]I'm out of here.[w:1000000000] ", {X = 91, Y = 210}, nil, true, 1)
					end
				elseif timer == 35 then
					table.insert(HuesosSuelo, {Misil = CreateProjectileAbs("Bullets/Bones/Body", 10, 0), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Scale = {MaxHeight = 200, Vel = 20}, Duration = 1/0})
					Audio.PlaySound("pierce")
				end
			elseif timer == 120 then
				Dialog("", "", "", "", 1)
				Encounter.Call("SetHead", "Please")
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					Bubble("[noskip][font:papyrus][voice:papyrus]EN SERIO?!", "rightwide", 490.5, 395, 40, 90, 1)
				else
					Bubble("[noskip][font:papyrus][voice:papyrus]REALLY?!", "rightwide", 490.5, 395, 40, 90, 1)
				end
			elseif timer == 121 then
				if Bubbles[1] and not Bubbles[1].Activo then
					Encounter.Call("SetHead", "Power")
					Encounter["Jaw"].MoveTo(Encounter["Head"].x, Encounter["Head"].y - 24)
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus]No puedes\nescapar de tus\nproblemas.", "rightwide", 490.5, 395, 40, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus]You can't run\naway from your\nproblems!", "rightwide", 490.5, 395, 40, 90, 1)
					end
				else
					timer = timer - 1
				end
			elseif timer == 122 then
				if Bubbles[1] and not Bubbles[1].Activo then
					Encounter.Call("SetHead", "Please")
					Encounter["Jaw"].MoveTo(Encounter["Head"].x, Encounter["Head"].y - 20)
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Bubble("[noskip][font:papyrus][voice:papyrus]Por favor solo\n[color:f2c900]perdoname[color:000000]...", "rightwide", 490.5, 395, 34, 90, 1)
					else
						Bubble("[noskip][font:papyrus][voice:papyrus]Please just [color:f2c900]spare[color:000000]\nme...", "rightwide", 490.5, 395, 34, 90, 1)
					end
				else
					timer = timer - 1
				end
			elseif timer == 123 then
				if Bubbles[1] and not Bubbles[1].Activo then
					if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 6, 6) == "0" then
						SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 5).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 7))
						if GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") == "1111111" then
							SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 9).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 11))
							Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 10}
						end
					end
					for i=1,#HuesosSuelo do
						local bullet = HuesosSuelo[i - tableaux]
						bullet.Misil.Remove()
						if bullet.Head then
							bullet.Head.Remove()
						end
						if bullet.Legs then
							bullet.Legs.Remove()
						end
						bullet = nil
						table.remove(HuesosSuelo, i - tableaux)
						tableaux = tableaux + 1
					end
					tableaux = 0
					Heart.Remove()
					Heart = nil
					Player.sprite.alpha = 1
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						Encounter["enemies"][1]["randomdialogue"] = {"[effect:none][font:papyrus][voice:papyrus]POR FAVOR...", "[effect:none][font:papyrus][voice:papyrus][color:f2c900]PERDONAME[color:000000]...", "[effect:none][font:papyrus][voice:papyrus]TE LO RUEGO..."}
					else
						Encounter["enemies"][1]["randomdialogue"] = {"[effect:none][font:papyrus][voice:papyrus]PLEASE...", "[effect:none][font:papyrus][voice:papyrus][color:f2c900]SPARE[color:000000] ME...", "[effect:none][font:papyrus][voice:papyrus]I'M BEGGING YOU..."}
					end
					Encounter["nextwaves"] = {"Spare"}
					State("DEFENDING")
				else
					timer = timer - 1
				end
			end
		end
	end
	for i=1,#GB do
		local gb = GB[i - tableaux]
		if not gb.X then
			gb.X = gb.Sprite.x
		end
		if not gb.Y then
			gb.Y = gb.Sprite.y
		end
		if gb.Type == "Papyrus" then
			gb.distance = 26
		elseif gb.Type == "Sans" then
			gb.distance = 38
		end
		gb.Sprite.xscale = (gb.Scale or 1)
		if gb.Animacion then
			if not gb.Animacion.timer then
				gb.Animacion.timer = 0
			end
			gb.Animacion.timer = gb.Animacion.timer + 1
			gb.X = gb.Animacion.DatosIniciales.X + (gb.Animacion.DatosFinales.X - gb.Animacion.DatosIniciales.X)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Y = gb.Animacion.DatosIniciales.Y + (gb.Animacion.DatosFinales.Y - gb.Animacion.DatosIniciales.Y)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Sprite.MoveTo(gb.X, gb.Y)
			while gb.Animacion.DatosIniciales.rotation >= 360 or gb.Animacion.DatosIniciales.rotation < 0 do
				if gb.Animacion.DatosIniciales.rotation < 0 then
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation + 360
				else
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation - 360
				end
			end
			while gb.Animacion.DatosFinales.rotation >= 360 or gb.Animacion.DatosFinales.rotation < 0 do
				if gb.Animacion.DatosFinales.rotation < 0 then
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation + 360
				else
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation - 360
				end
			end
			if gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation <= 180 and gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation >= -180 then
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (gb.Animacion.DatosIniciales.rotation - gb.Animacion.DatosFinales.rotation)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			else
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (360 - (gb.Animacion.DatosFinales.rotation - 180 + gb.Animacion.DatosIniciales.rotation - 180)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30)))))
			end
			if gb.Animacion.timer >= (gb.Animacion.VelAppearing or 30) then
				gb.Animacion = nil
				gb.Done = true
			end
		else
			if gb.Rotation and not gb.Done then
				gb.Sprite.rotation = gb.Rotation
			end
			gb.Delay = gb.Delay - 1
		end
		if gb.Vel then
			gb.X = gb.X - gb.Vel*math.sin(math.rad(gb.Sprite.rotation))
			gb.Y = gb.Y + gb.Vel*math.cos(math.rad(gb.Sprite.rotation))
			gb.Vel = gb.Vel*1.1
			if gb.X < -100 or gb.X > 740 or gb.Y < -100 or gb.Y > 580 then
				gb.Vel = 0
			end
		end
		gb.Sprite.MoveTo(gb.X, gb.Y)
		if (gb.Delay < 0 and gb.Type == "Papyrus") or (gb.Delay < 6 and gb.Type == "Sans") then
			if gb.Delay == 5 then
				gb.Sprite.Set("Bullets/GB Sans/1")
			elseif gb.Delay == 3 then
				gb.Sprite.Set("Bullets/GB Sans/2")
			elseif gb.Delay == 1 then
				gb.Sprite.Set("Bullets/GB Sans/3")
			elseif gb.Delay == -1 then
				if gb.Type == "Papyrus" then
					gb.Sprite.Set("Bullets/GB Papyrus/1")
				else
					gb.Sprite.SetAnimation({"Bullets/GB Sans/4","Bullets/GB Sans/5"}, 0.04)
				end
				gb.Vel = 2
				Audio.PlaySound("gasterfire")
			elseif gb.Delay <= -2 then
				if gb.Duration > 0 then
					gb.Duration = gb.Duration - 1
					if not gb.Laser then
						gb.Laser = {Misil = CreateProjectileAbs("Bullets/GB Laser 2", gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation))), Cuerpo = CreateProjectileAbs("Pixel", gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation))), Rafaga = CreateProjectileAbs("Bullets/GB Rafaga 1", gb.X + (-1 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (-1 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))}
						gb.Laser.Misil.sprite.xscale = 0
						gb.Laser.Misil.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Cuerpo.sprite.Scale(0, 0)
						gb.Laser.Cuerpo.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Rafaga.sprite.Scale(0, 0)
						gb.Laser.Rafaga.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Rafaga.sprite.SetAnimation({"Bullets/GB Rafaga 1", "Bullets/GB Rafaga 2"}, 0.08)
						gb.Laser.Scale = 0
					else
						gb.Laser.Misil.MoveToAbs(gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						if gb.Laser.Misil.sprite.xscale < 0.9*gb.Sprite.xscale and gb.Laser.Scale == 0 then
							gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
						else
							gb.Laser.Scale = gb.Laser.Scale + 50
							gb.Laser.Misil.sprite.xscale = 0.9*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
						end
						gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - 37)
						gb.Laser.Cuerpo.MoveToAbs(gb.X + (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Rafaga.sprite.Scale(gb.Laser.Misil.sprite.xscale, gb.Laser.Misil.sprite.xscale)
						gb.Laser.Rafaga.MoveToAbs(gb.X + (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
					end
					if not shake[1] then
						shake = {math.random(-4, 4), math.random(-4, 4)}
					end
				else
					gb.Laser.Misil.SetVar("No Damage", true)
					gb.Laser.Cuerpo.SetVar("No Damage", true)
					gb.Laser.Rafaga.SetVar("No Damage", true)
					if gb.Laser.Misil.sprite.xscale > 0 then
						gb.Laser.Misil.MoveToAbs(gb.X + (11 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (11 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale - 0.05*gb.Sprite.xscale
						gb.Laser.Misil.sprite.alpha = gb.Laser.Misil.sprite.xscale
						gb.Laser.Cuerpo.sprite.Scale(62*gb.Laser.Misil.sprite.xscale, gb.X + (22 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)) - 37)
						gb.Laser.Cuerpo.MoveToAbs(gb.X + (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 + gb.Laser.Cuerpo.sprite.yscale/2 + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Cuerpo.sprite.alpha = gb.Laser.Misil.sprite.xscale
						gb.Laser.Rafaga.sprite.Scale(gb.Laser.Misil.sprite.xscale, gb.Laser.Misil.sprite.xscale)
						gb.Laser.Rafaga.MoveToAbs(gb.X + (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (22 - 23*gb.Laser.Misil.sprite.xscale + gb.Laser.Cuerpo.sprite.yscale + gb.distance*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Rafaga.sprite.alpha = gb.Laser.Misil.sprite.xscale
					else
						gb.Laser.Misil.Remove()
						gb.Laser.Cuerpo.Remove()
						gb.Laser.Rafaga.sprite.StopAnimation()
						gb.Laser.Rafaga.Remove()
						gb.Sprite.Remove()
						gb = nil
						table.remove(GB, i - tableaux)
						tableaux = tableaux + 1
					end
				end
			end
		end
		if gb and shake then
			gb.Sprite.MoveTo(gb.X + (shake[1] or 0), gb.Y + (shake[2] or 0))
			if gb.Laser then
				gb.Laser.Misil.Move((shake[1] or 0), (shake[2] or 0))
				gb.Laser.Cuerpo.Move((shake[1] or 0), (shake[2] or 0))
				gb.Laser.Rafaga.Move((shake[1] or 0), (shake[2] or 0))
			end
		end
	end
	tableaux = 0
	Encounter.Call("PapsMoveTo", {Paps.X + (shake[1] or 0), Paps.Y + (shake[2] or 0)})
	if phase == 3 then
		Encounter["Sans"]["Legs"].MoveTo(Sans.X + (shake[1] or 0), Sans.Y + (shake[2] or 0))
		if progress == 2 then
			Encounter["Undyne"]["Legs"].MoveTo(Undyne.X + (shake[1] or 0), Undyne.Y + (shake[2] or 0))
		end
	end
	Encounter.Call("StatusMoveTo", {320 + (shake[1] or 0), 70.5 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Fight", 87 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Act", 240 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Item", 400 + (shake[1] or 0), 27 + (shake[2] or 0)})
	Encounter.Call("ButtonMoveTo", {"Mercy", 555 + (shake[1] or 0), 27 + (shake[2] or 0)})
	if Heart then
		Arena.MoveTo(320 + (shake[1] or 0), 90 + (shake[2] or 0), false, true)
		Heart.MoveTo(Pos.X + (shake[1] or 0), Pos.Y + (shake[2] or 0))
	end
	for i=1,#Spears1 do
		local Datos = Spears1[i]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		if Datos.Timer < 15 then
			Datos.Timer = Datos.Timer + 1
			Datos.PX = Datos.X + 18/15*Datos.Timer
			Datos.Sprite.alpha = 1/15*Datos.Timer
		end
		Datos.Sprite.MoveTo(Datos.PX + (shake[1] or 0), Datos.Y + (shake[2] or 0))
	end
	for i=1,#Spears2 do
		local Datos = Spears2[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		Datos.X = Datos.X + Datos.Vel*math.cos(math.rad(Datos.Direction))
		Datos.Y = Datos.Y + Datos.Vel*math.sin(math.rad(Datos.Direction))
		Datos.Sprite.MoveTo(Datos.X + (shake[1] or 0), Datos.Y + (shake[2] or 0))
		Datos.Sprite.rotation = Datos.Direction
		Datos.Timer = Datos.Timer + 1
		if Datos.Timer <= 10 then
			Datos.Sprite.alpha = 1/10*Datos.Timer
		else
			Datos.Sprite.alpha = 1/10*(20 - Datos.Timer)
			if Datos.Timer >= 20 then
				Datos.Sprite.Remove()
				table.remove(Spears2, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	for i=1,#Bones do
		local Datos = Bones[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		Datos.X = Datos.X + Datos.Vel
		Datos.Body.sprite.yscale = Datos.Scale
		Datos.Legs.sprite.rotation = 180
		Datos.Body.MoveToAbs(Datos.X + (shake[1] or 0), Datos.Y + (shake[2] or 0))
		Datos.Head.MoveToAbs(Datos.X + (shake[1] or 0), Datos.Y + Datos.Scale/2 + 2.5 + (shake[2] or 0))
		Datos.Legs.MoveToAbs(Datos.X + (shake[1] or 0), Datos.Y - Datos.Scale/2 - 2.5 + (shake[2] or 0))
	end
	tableaux = 0
	for i=1,#HuesosSuelo do
		local bullet = HuesosSuelo[i - tableaux]
		if not bullet.X then
			bullet.X = bullet.Misil.absx
		end
		if not bullet.Y then
			bullet.Y = bullet.Misil.absy
		end
		if not bullet.Scale.Direction then
			bullet.Scale.Direction = "Up"
		end
		if not bullet.Scale.Current then
			bullet.Scale.Current = 0
		end
		if not bullet.Rotacion then
			bullet.Rotacion = 0
		end
		if bullet.Scale.Current < bullet.Scale.MaxHeight and bullet.Scale.Direction == "Up" then
			bullet.Scale.Current = math.min(bullet.Scale.Current + bullet.Scale.Vel, bullet.Scale.MaxHeight)
			if bullet.Scale.Current >= bullet.Scale.MaxHeight then
				bullet.Scale.Direction = "Waiting"
			end
		elseif bullet.Scale.Direction == "Waiting" then
			if not bullet.Timer then
				bullet.Timer = 0
			end
			bullet.Timer = bullet.Timer + 1
			if bullet.Timer >= (bullet.Duration or 30) then
				bullet.Scale.Direction = "Down"
			end
		elseif bullet.Scale.Current > 0 and bullet.Scale.Direction == "Down" then
			bullet.Scale.Current = math.max(bullet.Scale.Current - bullet.Scale.Vel, 0)
		end
		bullet.Misil.sprite.yscale = bullet.Scale.Current
		bullet.Misil.sprite.rotation = bullet.Rotacion
		bullet.Misil.MoveToAbs(bullet.X + (shake[1] or 0) - bullet.Scale.Current/2*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + bullet.Scale.Current/2*math.cos(math.rad(bullet.Rotacion)))
		if bullet.Head then
			bullet.Head.MoveToAbs(bullet.X + (shake[1] or 0) - (bullet.Scale.Current + 2.5)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) + (bullet.Scale.Current + 2.5)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Head.sprite.rotation = bullet.Rotacion
		end
		if bullet.Legs then
			bullet.Legs.MoveToAbs(bullet.X + (shake[1] or 0) + (bullet.Scale.Current + 2.5)*math.sin(math.rad(bullet.Rotacion)), bullet.Y + (shake[2] or 0) - (bullet.Scale.Current + 2.5)*math.cos(math.rad(bullet.Rotacion)))
			bullet.Legs.sprite.rotation = bullet.Rotacion + 180
		end
		if bullet.Scale.Current <= 0 and bullet.Scale.Direction == "Down" then
			bullet.Misil.Remove()
			if bullet.Head then
				bullet.Head.Remove()
			end
			if bullet.Legs then
				bullet.Legs.Remove()
			end
			bullet = nil
			table.remove(HuesosSuelo, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#ShakeL do
		local Datos = ShakeL[i]
		if not Datos.X then
			Datos.X = Datos.Sprite.x
		end
		if not Datos.Y then
			Datos.Y = Datos.Sprite.y
		end
		Datos.Sprite.MoveTo(Datos.X + (shake[1] or 0), Datos.Y + (shake[2] or 0))
	end
	for i=1,#Shards do
		local Datos = Shards[i - tableaux]
		Datos.Pos.X = Datos.Pos.X + Datos.X/10
		Datos.Pos.Y = Datos.Pos.Y + Datos.Y/10
		Datos.Sprite.MoveTo(Datos.Pos.X + (shake[1] or 0), Datos.Pos.Y + (shake[2] or 0))
		Datos.Y = Datos.Y - 1
		if Datos.Sprite.y <= -10 then
			Datos.Sprite.Remove()
			table.remove(Shards, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
end

function OnHit()
	
end